package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PayInfo;
import com.ruoyi.system.service.IPayInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付密码Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/system/info")
public class PayInfoController extends BaseController
{
    @Resource
    private IPayInfoService payInfoService;

    /**
     * 查询支付密码列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayInfo payInfo)
    {
        startPage();
        List<PayInfo> list = payInfoService.selectPayInfoList(payInfo);
        return getDataTable(list);
    }

    /**
     * 导出支付密码列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "支付密码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayInfo payInfo)
    {
        List<PayInfo> list = payInfoService.selectPayInfoList(payInfo);
        ExcelUtil<PayInfo> util = new ExcelUtil<PayInfo>(PayInfo.class);
        util.exportExcel(response, list, "支付密码数据");
    }

    /**
     * 获取支付密码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(payInfoService.selectPayInfoByUserId(userId));
    }

    /**
     * 新增支付密码
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "支付密码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayInfo payInfo)
    {
        return toAjax(payInfoService.insertPayInfo(payInfo));
    }

    /**
     * 修改支付密码
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "支付密码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayInfo payInfo)
    {
        return toAjax(payInfoService.updatePayInfo(payInfo));
    }

    /**
     * 删除支付密码
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "支付密码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(payInfoService.deletePayInfoByUserIds(userIds));
    }
}
